/**
 * @param {number[]} T
 * @return {number[]}
 */
// 时间复杂度太高！
var dailyTemperatures = function (T) {
    let ans = new Array(T.length).fill(0);
    for (let i = 0; i < T.length - 1; i++) {
        let j = i + 1
        for (; j < T.length; j++) {
            ans[i]++
            if (T[j] > T[i]) break;
        }
        if (j == T.length && T[j - 1] <= T[i]) ans[i] = 0
    }
    return ans;
};



dailyTemperatures = function (T) {
    let ans = []
    let stack = []
    // stack.push(T.shift())
    while(T.length>0){
        debugger
        let count =0
        let p = T.shift()
        while(stack.length!=0){
            if(p<stack[stack.length-1]){
                stack.push(p)
            }else{
                stack.pop()
                count++;
            }
        }
        stack.push(p)
        ans.push(count)
    }
    return ans
}

console.log(dailyTemperatures([73, 74, 75, 71, 69, 72, 76, 73]));

